package com.java.demo.model;

/**
 * @auther zhangwj
 * @date 2021/1/5 下午1:32
 */
public class DecoratorPattern1 {

    public static void main(String[] args) {
        Phone HWPhone = new IPhone();
        PhoneColour phoneColour = new RadPhone(HWPhone);
        System.out.println(phoneColour.getColour());
    }
}

abstract class Phone {

    abstract String getName();
}

class IPhone extends Phone {

    @Override
    String getName() {
        return "IPhone";
    }
}

class HWPhone extends Phone {

    @Override
    String getName() {
        return "HW";
    }
}

abstract class PhoneColour extends Phone {
    private Phone phone;

    abstract String getColour();

    protected PhoneColour(Phone phone) {
        this.phone = phone;
    }

    @Override
    String getName() {
        return phone.getName();
    }
}

class RadPhone extends PhoneColour {

    protected RadPhone(Phone phone) {
        super(phone);
    }

    @Override
    String getColour() {
        return "rad " + getName();
    }
}